﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ToDoClear;
using System.Windows.Threading;
using ToDoClear.Motion;
namespace ToDoClear.HandleLogic
{
    public class IdleHandle : GestureHandle
    {
        private const string TAG = "IdleHandle";
        public   MainState GetSupportState()
        {
            
            return MainState.IdleState;
        }

        public void DragCompleted(object sender, DragCompletedGestureEventArgs e)
        {
            Log.d(TAG, "DragCompleted");
            /*
            Point cuPoint = e.GetPosition(ToDoCanvas.getInstance().RootCanvas);
            double dy = ToDoCanvas.getInstance().context.DragStartPoint.Y - cuPoint.Y;
            ToDoItem cuItem = ToDoCanvas.getInstance().cuList.Children[0] as ToDoItem;
            double disireH = ConstVar.ItemH - dy;
            //cuItem.Split(disireH);
            cuItem.Split(disireH);
            ToDoCanvas.getInstance().cuList.ReSize();
             */
        }

        public void DragDelta(object sender, DragDeltaGestureEventArgs e)
        {
            Log.d(TAG, "DragDelta");

            Point cuPoint = e.GetPosition(ToDoCanvas.getInstance().RootCanvas);
            double dx = cuPoint.X - ToDoCanvas.getInstance().context.DragStartPoint.X;
            double dy = cuPoint.Y - ToDoCanvas.getInstance().context.DragStartPoint.Y;

            if (Math.Abs(dx) > Math.Abs(dy))
            {
               // HandleManager.EnterState(MainState.HerDrag);

            }
            else
            {
                HandleManager.EnterState(MainState.VerDrag);
                ToDoCanvas.getInstance().cuList.RefreshVerDragOffset(cuPoint);
            }
          


            /*
            Point cuPoint = e.GetPosition(ToDoCanvas.getInstance().RootCanvas);
            double dy = ToDoCanvas.getInstance().context.DragStartPoint.Y - cuPoint.Y;
            ToDoItem cuItem = ToDoCanvas.getInstance().cuList.Children[0] as ToDoItem;
            double disireH = ConstVar.ItemH - dy;
            cuItem.Split(disireH);
            ToDoCanvas.getInstance().cuList.ReSize();*/
        }

        public void DragStarted(object sender, DragStartedGestureEventArgs e)
        {
            Log.d(TAG, "DragStarted");

           ToDoCanvas.getInstance().context.DragStartPoint= e.GetPosition(ToDoCanvas.getInstance().RootCanvas);
           ToDoCanvas.getInstance().context.DragStartOffset = ToDoCanvas.getInstance().cuList.Offset;
        }

        public void Flick(object sender, FlickGestureEventArgs e)
        {
            Log.d(TAG, "Flick");

            Log.d("handle", "VerticalVelocity:" + e.VerticalVelocity);
        }

        public void GestureBegin(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
        {
            Log.d(TAG, "GestureBegin");

        }

        public void GestureCompleted(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
        {
            Log.d(TAG, "GestureCompleted");

        }

        public void PinchCompleted(object sender, PinchGestureEventArgs e)
        {
            Log.d(TAG, "PinchCompleted");

        }

        public void PinchDelta(object sender, PinchGestureEventArgs e)
        {
            Log.d(TAG, "PinchDelta");

        }

        public void PinchStarted(object sender, PinchStartedGestureEventArgs e)
        {
            Log.d(TAG, "PinchStarted");

        }

        public void Tap(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
        {
            Log.d(TAG, "Tap");

        }

        public void Hold(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
        {
            Log.d(TAG, "Hold");

        }
    }
}
